/**
 * This file is part of the CAKIS project.
 * 
 * Copyright (c) 2009-2010 - Florian Arndt, Christian Kerl
 * 
 * @license GNU Lesser General Public License v3 <http://www.opensource.org/licenses/lgpl-3.0.html>
 * @since   04.05.2010
 * @version SVN: $Id: ExitCommand.java 155 2010-05-19 13:51:47Z f.aarndt@web.de $
 */

package org.cakis.client.commands;

import java.rmi.RemoteException;

import javax.microedition.lcdui.Command;
import javax.xml.rpc.JAXRPCException;

import org.cakis.client.CakisMIDlet;

/**
 * ExitCommand
 *
 * @author Florian Arndt
 */
public class ExitCommand extends AbstractCommand {
	private CakisMIDlet midlet;
	
	public ExitCommand(CakisMIDlet m) {
		super("Exit", Command.EXIT, 0);
		this.midlet = m;
	}
	
	public void execute() {
		if (!midlet.getOfflineHandler().getFlag()) {
			try {
				midlet.getService().endClientSession();
			} catch (RemoteException e) {
				e.printStackTrace();
				midlet.notifyDestroyed();
			} catch (JAXRPCException e) {
				midlet.notifyDestroyed();
			}
		}
		midlet.notifyDestroyed();
	}

}
